package cn.ava.ymcc.mq.listener;

import cn.ava.ymcc.domain.MessageEmail;
import cn.ava.ymcc.domain.MessageSms;
import cn.ava.ymcc.domain.MessageStation;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class OnLineCourseProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送课程上线消息给所有用户,因为数据量较大,而且不太重要,所以可以有容错,选择发送单向消息
     * @param messageStation
     */
    public void sendStationMessage(MessageStation messageStation){
        Message<MessageStation> message = MessageBuilder.withPayload(messageStation).build();
        rocketMQTemplate.sendOneWay("topic-course-online:tags-station", message);
    }

    /**
     * 课程发布,发送手机短信消息
     * @param messageSms
     */
    public void sendSmsMessage(MessageSms messageSms){
        Message<MessageSms> message = MessageBuilder.withPayload(messageSms).build();
        rocketMQTemplate.sendOneWay("topic-course-online:tags-sms", message);
    }

    /**
     * 发送邮件消息
     * @param messageEmail
     */
    public void sendEmailMessage(MessageEmail messageEmail){
        Message<MessageEmail> message = MessageBuilder.withPayload(messageEmail).build();
        rocketMQTemplate.sendOneWay("topic-course-online:tags-email", message);
    }

}
